using Gateway.Common.Entity;
using Gateway.Common.Enums;

namespace Gateway.Domain.Entities;

/// <summary>
/// 角色表
/// </summary>
public class Role : AggregateRootEntityBase
{
    public Role(string roleName = default, string roleAlias = default, string remark = default, int seqNo = 0)
    {
        RoleName = roleName;
        RoleAlias = roleAlias;
        Remark = remark;
        SeqNo = seqNo;
        this.RoleNo = "ROLE" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000);
    }

    /// <summary>
    /// 为了 初始化数据用的
    /// </summary>
    public void SetDefaultId()
    {
        this.Id = "default";
    }

    /// <summary>
    /// 更新
    /// </summary>
    public void Update(string roleName = default, string roleAlias = default, string remark = default, int seqNo = 0)
    {
        RoleName = roleName;
        RoleAlias = roleAlias;
        Remark = remark;
        SeqNo = seqNo;
    }

    /// <summary>
    /// 编号
    /// </summary>
    public string RoleNo { get; private set; }

    /// <summary>
    /// 角色别名
    /// </summary>
    public string RoleAlias { get; private set; }

    /// <summary>
    /// 角色名称
    /// </summary>
    public string RoleName { get; private set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; private set; }

    /// <summary>
    /// 序号
    /// </summary>
    public int SeqNo { get; private set; }

    /// <summary>
    /// 角色菜单集合
    /// </summary>
    public List<RoleMenu> RoleMenus { get; private set; }

    public List<RoleExtensionPermission> RoleExtensionPermissions { get; set; }

    /// <summary>
    /// 设置菜单权限
    /// </summary>
    /// <param name="menus"></param>
    public void SetMenus(List<string> menus)
    {
        RoleMenus = menus?.Select(p => new RoleMenu(Id, p)).ToList();
    }

    /// <summary>
    /// 设置扩展权限
    /// </summary>
    /// <param name="permission"></param>
    public void SetPermission(List<RoleExtensionPermission> permission)
    {
        RoleExtensionPermissions = permission;
    }

    public Role()
    {
    }
}